package wflow.remote.remote.processor;

import io.netty.channel.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import wflow.remote.remote.command.Command;
import wflow.remote.remote.command.CommandContext;
import wflow.remote.remote.command.CommandType;

public class EchoProcessor implements NettyRequestProcessor {
    private final static Logger logger = LoggerFactory.getLogger(EchoProcessor.class);

    @Override
    public void process(Channel channel, Command command) {
        byte[] body = command.getBody();
        logger.info(new String(body));
        Command response = new Command();
        response.setType(CommandType.ECHO);
        response.setOpaque(1L);
        response.setContext(new CommandContext());
        response.setBody(command.getBody());
        channel.writeAndFlush(response);
    }
}
